# 登录
import requests

login_url = "http://ihrm2-test.itheima.net/api/sys/login"
login_body = {"mobile": "13800000002", "password":"123456"}
resp = requests.post(login_url, json=login_body)
print("登录：", resp.json())
token = "Bearer " + resp.json().get("data")

# 新增员工 employee
add_emp = "http://ihrm2-test.itheima.net/api/sys/user"
add_body = {"username": "YG001", "mobile": "18210222334","workNumber": "123"}
headers = {"Authorization": token}
add_resp = requests.post(add_emp, headers=headers, json=add_body)
print("新增员工：", add_resp.json())

# 修改员工
modify_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/1551458237293801472"
headers = {"Authorization": token}
modify_body = {"username": "YG002","password": "123456","departmentId": "10086"}
resp_modify = requests.put(modify_emp_url, headers=headers, json=modify_body)
print("修改员工", resp_modify.json())

# 查询员工
query_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/1551458237293801472"
headers = {"Authorization": token}
query_resp = requests.get(query_emp_url, headers=headers)
print("查询员工：", query_resp.json())

# 删除员工
delete_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/1551458237293801472"
headers = {"Authorization": token}
delete_resp = requests.delete(delete_emp_url, headers=headers)
print("删除员工：", delete_resp.json())